﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBconnection;
using OutPutSimulation;
using RulesCore;

namespace simulation
{
    public class SIM
    {
        private static Dictionary<string, Cls> Classes = new Dictionary<string, Cls>();
        private static Dictionary<int, string[]> Rules = new Dictionary<int, string[]>();
        private List<string> BrokenRules = new List<string>();
        public static void Start()
        {
            InitSimulation();
        }

        public static void S_Add(string name, Guid id, string[] Params)
        {
            Classes[name].addObject(id, Params);
            Classes[name].CheckMyRules();
        }

        public static void S_Mod(string Name,Guid id,string PrmName,string nVal)
        {
            Classes[Name].SetVal(PrmName, id, nVal);
            Classes[Name].CheckMyRules();
        }

        public static void S_Delete(string name,Guid id)
        {
            Classes[name].DeleteObj(id);
        }

        private static void InitSimulation()
        {
            string[] Structs = DB.S_getClasses();
            foreach (string struc in Structs)
            {
                Classes.Add(struc, new Cls(struc));
                string[] prms = DB.S_getPrms(struc);
                foreach (string prm in prms)
                {
                    Classes[struc].addPrm(prm);
                }
                Classes[struc].myRules();
            }

            string[] rules = DB.GetRulesList();
            int index=1;
            foreach (string rule in rules)
            {
                Rules.Add(index, DB.GettingRule_Text(rule));
                index++;
            }
        }

        public void CheckRules()
        {
            
        }

    }
}
